<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Canvas 示例</title>
</head>

<body>
    <canvas id="myCanvas" width="200" height="100"></canvas>

    <script>
        window.onload = () => {
            // 1. 获取canvas对象
            const c = document.getElementById("myCanvas");
            // 2.获取上下文环境对象context
            let ctx = c.getContext("2d");
            // 3. 绘制图形
            ctx.fillStyle = "#FF0000";
            ctx.fillRect(0, 0, 150, 75);
        }
    </script>
</body>

</html>